<include file="../header" />

<script type="text/javascript" src="/Template/js/vue.min.js"></script>

<body class="J_scroll_fixed" id="container">
<script type="text/javascript">
    $(function () {
        $("input[name=checkAll]").click(function () {
            var checkboxs = $("input.checkItem");
            if ($("input[name=checkAll]").is(':checked')) {
                for (var i = 0; i < checkboxs.length; i++) {
                    checkboxs[i].checked = true;
                }
            } else {
                for (var i = 0; i < checkboxs.length; i++) {
                    checkboxs[i].checked = false;
                }
            }
        });

        $(".search").click(function () {
            $("select[name=customerId]").show();
            $("select[name=customerId]").empty();
            $("select[name=customerId]").append("<option value='0'></option>");
            var customerName = $("input[name=customerName]").val();

            if (customerName == "") {
                alert("请填写【用户昵称】");
                $("input[name=customerName]").focus();
                return false;
            }

            var data = {};
            data.customerName = customerName;
            $.ajax({
                url: "/admin/customer/customerList",
                type: "post",
                data: data,
                dataType: "JSON",
                beforeSend: function () {
                    $("#loadingToast").show();
                },
                complete: function () {
                    $('#loadingToast').hide();
                },
                success: function (data) {
                    if (data.code != 200) {
                        alert(data.msg);
                        return false;
                    }
                    for (var i = 0; i < data.list.length; i++) {
                        $("select[name=customerId]").append("<option value='" + data.list[i].customer_id + "'>" + data.list[i].nickname + "</option>");
                    }
                    if (data.list.length > 0) {
                        $(".custmerList").show();
                    } else {
                        $(".addRow").hide();
                        $(".custmerList").hide();
                    }
                    return false;
//                window.location.href = "/wechat/userCenter/payInfo/id/"+data.order_id;
                },
            })
            return false;
        });

        $("select[name='customerId']").change(function () {
            $(".addRow").hide();
            var customerId = $("select[name='customerId']").val();
            if(customerId == 0){
                return false;
            }else{
                $(".addRow").show();
            }
        });

        $(".addRow").click(function () {
            var customerId = $("select[name='customerId']").val();
            if(customerId == 0){
                return false;
            }else{
                var customerIdStr = $("input[name='customerIdStr']").val();
                if(customerIdStr != ""){
                    customerIdStr += ",";
                }
                customerIdStr += customerId;
                $("input[name='customerIdStr']").val(customerIdStr);

                var customerNameStr = $("input[name='customerNameStr']").val();
                if(customerNameStr != ""){
                    customerNameStr += "，";
                }
                customerNameStr += $("select[name='customerId']").find("option:selected").text();;
                $("input[name='customerNameStr']").val(customerNameStr);
                $("select[name='customerId']").find("option").eq(0).prop("selected",true);
                $(".addRow").hide();
            }
        });

        $(".clearCustomer").click(function () {
            if(confirm("是否加清空单独通知列表？")) {
                $("input[name='customerIdStr']").val("");
                $("input[name='customerNameStr']").val("");
            }
        });

        $("button.btn_submit").click(function () {
            if ($("input[name=showName]").val() == "") {
                alert("【通知名称】不能为空");
                $("input[name=showName]").focus();
                return false;
            }

            if ($("input[name=notifyName]").val() == "") {
                alert("【通知标签】不能为空");
                $("input[name=notifyName]").focus();
                return false;
            }

            var checkboxs = $("input.checkItem");
            var id = "";
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked == true) {
                    if (id != "") {
                        id += ",";
                    }
                    id += checkboxs[i].name;
                }
            }
            $("input[name=roleId]").val(id);
            $("button.btn_submit").hide();
        })

    })

</script>
<style type="text/css">
    .btn,.btn-danger,.btn-info,.btn-success,.btn-warning{
        width: 50px;
        /*height: 18px;*/
        padding: 2px 0px 2px 0px;
        margin: 1px 0px 1px 0px;
    }
</style>
<div class="wrap jj">
    <div class="common-form">
        <form method="post" class="form-horizontal J_ajaxForm" action="{:U('Notify/addPost')}">
            <fieldset>
                <input type="hidden" name="user_id" value="{$user.user_id}"/>
                <fieldset>
                    <div class="control-group">
                        <label class="control-label">通知名称:</label>
                        <div class="controls">
                            <input type="text" class="input" name="showName" value="" placeholder="例如：分销成品订单下单">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">通知标签:</label>
                        <div class="controls">
                            <input type="text" class="input" name="notifyName" value="" placeholder="例如：createFinishedOrder">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">备注:</label>
                        <div class="controls">
                            <input type="text" class="input" style="width: 600px" name="note" value="">
                        </div>
                    </div>
                    <hr class="half-rule">
                    <table class="table table-hover table-bordered" id="viewTabs" style="width: 750px; margin-left: 90px">
                        <thead>
                        <tr>
                            <th style="min-width: 10px; width: 10px"><input type="checkbox" name="checkAll"></th>
                            <th style="min-width: 100px; width: 100px">通知角色</th>
                            <th style="min-width: 100px; width: 600px">人员</th>
                        </tr>
                        </thead>
                        <tbody>
                        <foreach name="roleArr" item="vo">
                            <tr>
                                <php>
                                    if(in_array($vo["id"], $notifyRoleArr)){
                                    $role_checked = "checked";
                                    }else{
                                    $role_checked = "";
                                    }
                                </php>
                                <td><input type="checkbox" class="checkItem" name="{$vo.id}" {$role_checked}></td>
                                <td style="font-size: 1rem">{$vo.id}.{$vo.name}</td>
                                <php>
                                    $i = 0;
                                    $nameStr = "";
                                    foreach($allEmployeeList as $employee) {
                                    $employeeRoleList = explode(',', $employee["role"]);
                                    if (in_array($vo["id"], $employeeRoleList)) {
                                    if($i != 0){
                                    if($i != 9){
                                    $nameStr .= "、 ";
                                    }else{
                                    $nameStr .= "<br/>";
                                    }
                                    }
                                    $nameStr .= $employee["admin_name"];
                                    $i++;
                                    }
                                    }
                                </php>
                                <td style="font-size: 1rem; color: #1cc385">{$nameStr}</td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                    <input type="hidden" name="roleId" value="" style="width: 200px"/>

                    <hr class="half-rule">
                    <div class="control-group">
                        <label class="control-label">用户昵称：</label>
                        <div class="controls">
                            <input type="text" class="input" name="customerName" value="" style="width: 100px">
                            <a class="btn btn-success search">搜索</a>
                        </div>
                        <div class="controls custmerList" style="display: none">
                            <select name="customerId" style="width: auto">
                                <option value='0'></option>
                            </select>
                            <a class="btn btn-success addRow" style="display: none">添加</a>
                        </div>
                    </div>

                    <div class="control-group">
                        <label class="control-label">单独通知：</label>
                        <div class="controls">
                            <php>
                                $customerNameStr = "";
                                foreach ($notifyCustomerList as $notifyCustomer) {
                                if(isNullOrEmpty(!$customerNameStr)){
                                $customerNameStr .= "，";
                                }
                                $customerNameStr .= $notifyCustomer["nickname"];
                                }
                            </php>
                            <input type="text" style="width: 600px" class="input" name="customerNameStr" value="{$customerNameStr}" readonly>
                            <a class="btn btn-danger clearCustomer">清空</a>
                        </div>
                    </div>
                    <input type="hidden" name="customerIdStr" value="{$info.customer_id}" style="width: 200px"/>
            </fieldset>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn_submit">添加</button>
                <a class="btn" href="__URL__">返回</a>
            </div>
        </form>
    </div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>